package pers.zw.study.mysql;

import org.junit.Test;
import pers.zw.study.mysql.utils.JdbcUtils_DBCP;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DataSourceTest {

    @Test
    public void dbcpDataSourceTest() {
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        try {
            connection = JdbcUtils_DBCP.getConnection();
            String sql = "INSERT INTO student VALUES(?, ?, ?, ?, ?)";
            statement = connection.prepareStatement(sql);
            statement.setString(1, "111");
            statement.setString(2, "sb");
            statement.setString(3, "男女");
            statement.setString(4, "1998-02-27");
            statement.setString(5, "123413241");

            statement.executeUpdate();

            resultSet = statement.getGeneratedKeys();
            if (resultSet.next()) {
                System.out.println(resultSet.getObject("s_no"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils_DBCP.release(connection, statement, resultSet);
        }
    }
}
